<!--# layout("/common/mallout.html",{"jsBase":"/js/order/settlement/"}){ -->

<link rel="stylesheet" href="http://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop/mall/style/gallery.css">
<link rel="stylesheet" href="https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop%2Fmall%2Fstyle%2Fproduct.css">
<script src="http://www.11ziyun.com/js/region.js"></script>
<style>
    .address_tab span{padding: 0px;}
    .section{overflow:inherit;}
</style>
<div class="section">
    <!------------------------------------>
    <div class="gallery-sortbar">
        <input type="hidden" value="${keywords}" id="keywords">
        <input type="hidden" id="orderValue" value="" >

        <div class="sortbar">
            <span class="action-sort"  id="default">默认<i></i></span>
            <span class="action-sort" id="price">总价<i></i></span>
            <span class="action-sort" id="buy_count">销量<i></i></span>
            <span class="simuselect"><strong>默认</strong><s></s>
            	<ul>
                    <li attribute="">默认</li>
                    <li attribute="price asc">按价格 从低到高</li>
                    <li attribute="price desc">按价格 从高到低</li>
                    <li attribute="buy_count asc">按销量 从高到低</li>
                    <li attribute="buy_count desc">按销量 从低到高</li>
                    <li attribute="buy_w_count desc">周购买次数</li>
                    <li attribute="buy_t_count desc">总购买次数</li>
                </ul>
                <select name="orderBy" id="orderBy" class="action-orderby">
                    <option value="" selected="">默认</option>
                    <option value="price asc">按价格 从低到高</option>
                    <option value="price desc">按价格 从高到低</option>
                    <option value="buy_count asc">按销量 从高到低</option>
                    <option value="buy_count desc">按销量 从低到高</option>
                    <option value="buy_w_count desc">周购买次数</option>
                    <option value="buy_t_count desc">总购买次数</option>
                </select>
            </span>
            <span class="inputPrice">￥<input type="number" min="0" class="buy_count_num price_start"></span>
            <span style="border:none;">——</span>
            <span class="inputPrice">￥<input type="number" min="0" class="buy_count_num price_end"></span>
            <em>
                <input type="checkbox" id="self">
                <label class="gallery-showmode" for="self"><s></s>紫云自营</label>

            </em>
            <em>
                <input type="checkbox" id="isQuote">
                <label  class="gallery-showmode" for="isQuote"><s></s>报价商品</label>

            </em>
            <em>
                <input type="checkbox" id="havaGoods">
                <label  class="gallery-showmode" for="havaGoods"><s></s>仅显示有货</label>
            </em>
        </div>
        <div class="mini-pageview">
            <!--地址-->
            <!--<span class="address_text" style="vertical-align: top;"><a>湖北 武汉市 江汉区</a><s></s>-->
                <!--<div class="address_select">-->
                    <!--<div class="address_tab">-->
                        <!--<span class="atver"><i>湖北</i></span>-->
                        <!--<span><i>武汉</i></span>-->
                        <!--<span><i>江汉区</i></span>-->
                    <!--</div>-->
                    <!--<div style="display:none;">-->
                        <!--<select class="address_op"></select>-->
                            <!--<select class="address_op"></select>-->
                                <!--<select class="address_op"></select>-->
                    <!--</div>-->
                    <!--<div class="address_con">-->

                    <!--</div>-->
                    <!--<div class="address_con">-->

                    <!--</div>-->
                    <!--<div class="address_con">-->

                    <!--</div>-->
                <!--</div>-->
            <!--</span>-->
            <!--分页-->
            <span class="page-action" count="">
                 <span id="headCount"></span>
               <button class="h_right flip next ">></button>
                <button class="h_right flip prev"><</button>
                  <span class="page-current">1</span>/<span class="page-total"></span>

                 <!--<a href="javascript:void(0);" class="flip prev"><</a>-->
                  <!--<i>-->
                    <!--<span class="page-count">-->
                    <!--<span class="page-current">1</span>/<span class="page-total"></span>-->
                    <!--</span>-->
                  <!--</i>-->
                <!--<a href="javascript:void(0);" class="flip next">></a>-->

           </span>
        </div>
    </div>
    <!-----------------显示列表--------------------->
    <div class="gallery-show"></div>
    <div align="center" class="pageFloot" id="demo7"></div>
    <script type="text/html" id="productList">
        <div class="gallery-grid">
            <ul>

                {{ if products.length < 1}}
                <li class="shop_mood_list">暂无商品</li>
                {{else}}

                {{each productSearchVo as  goods}}

                <li class="goods-item ">
                <a href="/mall/skuProductDetails.do?goodsId={{goods['goodsId']}}&goodsType={{goods['goodsType']}}" target="_blank">
                    <div class="goods-pic">
                        <a href="/mall/skuProductDetails.do?goodsId={{goods['goodsId']}}&goodsType={{goods['goodsType']}}" target="_blank">
                            {{if goods['defaultImage'] == null}}
                            <img src="https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop/mall/image/pic_pop_02.png" class="show">
                            {{else}}
                            <img src="${imagepath}/{{goods['defaultImage']}}?x-oss-process=image/resize,m_pad,h_200,w_200" class="show">
                            {{/if}}
                        </a>
                    </div>
                    <div class="goods-price-pic-list">
                        <span class="goods-dis-l"></span>
                        <div class="goods-pric-dis">
                            <ul>
                                {{each goods['goodsImgUrls'] as image i}}
                                <li class="">
                                    <a href="javascript:;">
                                        <img src="${imagepath}/{{image}}?x-oss-process=image/resize,m_pad,h_200,w_200" class="show">
                                    </a>
                                </li>
                                {{/each}}

                            </ul>
                        </div>
                        <span class="goods-dis-r"></span>
                    </div>
                    <div class="goods-info">
                        <div class="goods-price-point">
                              <span class="goods-price">
                              	<font class="price">￥<b style="font-size: large">{{goods['popSinglePriceShow']}}</b></font>
                              </span>
                            <span class="goods-num">
                              	成交{{goods['buyCount'] == null ? 0 : goods['buyCount']}}单
                              </span>
                        </div>
                        <div class="goods-name">
                            <p>
                                <a target="_blank" href="/mall/skuProductDetails.do?goodsId={{goods['goodsId']}}&goodsType={{goods['goodsType']}}">{{goods['goodsName']}}</a>
                            </p>
                            <p>
                                <span><strong>{{goods['sellerName']}}</strong></span>
                                {{if goods['self'] == true}}
                                <i>自营</i>
                                {{/if}}
                            </p>
                        </div>
                    </div>

                  {{if goods['goodsType'] == 'print' || goods['goodsType'] == 'fast'}}
                    <div class="goods-offer">报价</div>
                    {{/if}}
                    <div class="goods-buy">
                        <a href="/mall/skuProductDetails.do?goodsId={{goods['goodsId']}}&goodsType={{goods['goodsType']}}" target="_blank">立即购买</a>
                    </div>
                </a>
                </li>
                {{/each}}
                {{/if}}
            </ul>
        </div>

    </script>
    <!-------------------------------------->
</div>


<!--#} -->
<script>
    layui.use(['index','laypage','element'], function(){

    var goodsSearchParamDto = {};
    goodsSearchParamDto['keyword'] = $("input#keywords").val();

    doAjax("/mall/searchGoods.json","post",{"goodsSearchParamDto":JSON.stringify(goodsSearchParamDto)},function (ret) {
        if(ret.code != 1 || ret.data.productSearchVo.length == 0) {
            var goods = "<div style=\"height:320px; background:url('https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop/mall/image/pic_pop_06.png') center center no-repeat; text-align:center;  font-size:22px; color:rgb(208,208,208);overflow:hidden;\"><p style=\"margin-top:250px;\">暂无商品,亲！</p></div>";
            $("div.gallery-show").html('');
            $("div.gallery-show").html(goods);
            $("#headCount").hide();
            page(0,1);
        }else{
            var html = template("productList",ret.data);
            $(".gallery-show").html(html);
            $(".page-total").html(ret.data.totalPage);
            page(ret.data.totalRows,ret.data.curPage);
            $("#headCount").show();
            $("#headCount").html("共"+ret.data.totalRows+"条");
        }
    });

    $(document).ready(function(){

        //搜索下拉
        $(".simuselect,.page-count").hover(function(){
            $(this).find('ul').show();
        },function(){
            $(this).find('ul').hide();
        });

        $(".simuselect ul li").on('click',function(){
            $(".simuselect strong")	.text($(this).text());
            $(this).parents('ul').hide();
            //修改select的值
            var sortMethd = $(this).attr('attribute');
            $("input#orderValue").val(sortMethd);
            // $('.action-sort').removeClass('active').eq(0).addClass('active');   //选中"默认"
            $('.action-sort').removeClass('active');   //选中"默认"
            sortGoods(sortMethd);

        });

        //多选
        $(".gallery-showmode").on("click",function(){
            $('.page-current').html(1);
            if($(this).hasClass("active"))
            {
                $(this).removeClass('active');
            }
            else
            {
                $(this).addClass('active');

            }
            sortGoods($("input#orderValue").val());
        });


        //绑定排序事件
        $('.action-sort').on('click', function(){
            if($(this).attr("id") == "default"){
                $("input#orderValue").val("");
                $('.action-sort').removeClass('active');
            }else{
                if($(this).hasClass('active'))
                {
                    $(this).removeClass('active');
                    $("input#orderValue").val($(this).attr('id')+' desc');
                }
                else
                {
                    $(this).addClass('active').siblings().removeClass('active');
                    $("input#orderValue").val($(this).attr('id')+' asc');
                }
            }

            //修改下拉框值
            $(".simuselect strong").text( '默认' );

            var sortMethd =  $("input#orderValue").val();
            sortGoods(sortMethd);
        });
        //价格区间
        $(".buy_count_num").on("change",function(){
                var sortMethd =  $("input#orderValue").val();
            if(!$(this).val() && !$(this).parents("span.inputPrice").siblings("span.inputPrice").find("input").val()){
                sortGoods(sortMethd);
            }else if($(this).parents("span.inputPrice").siblings("span.inputPrice").find("input").val()){
                sortGoods(sortMethd);
            }

        })
        //前一页
        $('.page-action').on('click', '.flip.prev',function(){
            //$('.action-sort').removeClass('active').eq(0).addClass('active');   //选中"默认"

            var curPage = parseInt( $('.page-current').html() );
            var page = curPage-1;
            if(page<1){
                // $(this).css("background","lightgrey");
                return;
            }

            $('.page-current').html( page );

            $('#page').val( page );
            sortGoods( $("input#orderValue").val() );

        });

        //后一页
        $('.page-action').on('click', '.flip.next',function(){
            //$('.action-sort').removeClass('active').eq(0).addClass('active');   //选中"默认"

            var curPage = parseInt( $('.page-current').html() );
            var totalPage = parseInt( $('.page-total').html() );

            var page = curPage + 1;
            if(page>totalPage){
                return;
            }

            $('.page-current').html( page );

            $('#page').val( page );
            sortGoods( $("input#orderValue").val());

        });
        //绑定排序事件--end

    });

    //搜索
    function sortGoods(sortMethd){
        //排序方式
        var order = '0';
        switch (sortMethd){
            case 'price asc':
                order = 1;
                break;
            case 'price desc':
                order = 2;
                break;
            case 'buy_count desc':    //按销量从高到低
                order = 4;
                break;
            case 'buy_count asc':
                order = 3;
                break;
            case 'buy_w_count desc':
                order = 5;
                break;
            case 'buy_t_count desc':
                order = 6;
                break;
            default:
                order = 0;
                break;
        }


        //原生的查询字符串
        goodsSearchParamDto['order'] = order;
        //多选值
        $(".gallery-showmode").each(function () {
                var name = $(this).attr('for');
                var value = false;
            if(!$(this).hasClass("active")&&name=='havaGoods'){
                value = true;
            }else if($(this).hasClass("active")&&name!='havaGoods'){
                value = true;
            }
            goodsSearchParamDto[name] = value;
        });
        var price_start = $(".price_start").val();
        var price_end = $(".price_end").val();
        if(price_start && price_end){
            goodsSearchParamDto['beginPrice'] = price_start;
            goodsSearchParamDto['endPrice'] = price_end;
        }

        goodsSearchParamDto['pageNo'] = Number($('.page-current').html());

        sendQuery(goodsSearchParamDto);

    }
    function sendQuery(goodsSearchParamDto){
        doAjax("/mall/searchGoods.json","post",{"goodsSearchParamDto":JSON.stringify(goodsSearchParamDto)},function (ret) {
            if(ret.code != 1 || ret.data.productSearchVo.length == 0) {
                var goods = "<div style=\"height:320px; background:url('https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop/mall/image/pic_pop_06.png') center center no-repeat; text-align:center;  font-size:22px; color:rgb(208,208,208);overflow:hidden;\"><p style=\"margin-top:250px;\">暂无商品,亲！</p></div>";
                $("div.gallery-show").html('');
                $("div.gallery-show").html(goods);
                $("#headCount").hide();
                page(0,1);
            }else{
                var html = template("productList",ret.data);
                $(".gallery-show").html(html);
                $(".page-total").html(ret.data.totalPage);
                page(ret.data.totalRows,ret.data.curPage);
                $("#headCount").show();
                $("#headCount").html("共"+ret.data.totalRows+"条");
            }
        });
    }

    //地址
    $(".address_text").hover(function(){
        $(".address_select").show();
        if($(".address_tab span").index('.atver')!=-1)
        {
            $(".address_con").eq(0).show();
        }


    },function(){

        $(".address_select").hide();
        $(".address_con").hide().eq(1).show();
        $(".address_tab i").eq(2).text('请选择').hide();
        $(".address_tab span").removeClass('atver').eq(1).addClass('atver');
    })
    $(".address_tab span").each(function(i, o) {
        $(o).click(function(){
            $(o).addClass('atver').siblings().removeClass('atver');
            $(".address_con").hide().eq(i).show();
        })
    });
    $.select_add('address_op',region_Data,1323);//默认湖北武汉江汉区
    $(".address_con").each(function(i, o) {
        $(o).html($(".address_op").eq(i).html());
        $(o).find("option").each(function(index, element) {
            $(element).wrapAll(document.createElement("span"));
        });
        $(o).on('click','option',function(){
            $(".address_op").eq(i).val($(this).attr('value'))
            $(".address_tab span").eq(i).find('i').text($(this).text());
            var id=$(this).attr('value')
            add_div(region_Data,id,i);
        })
    });

    function add_div(jsonData,id,index)
    {
        getJsonLength=function(jsonData)
        {
            var jsonLength = 1;
            for(var item in jsonData){
                jsonLength++;
            }
            return jsonLength;

        };

        var len=getJsonLength(region_Data);

        if(index==0)
        {
            $(".address_con").eq(1).html('');
            $(".address_con").eq(2).html('');
            $(".address_tab i").eq(1).text('请选择');
            $(".address_tab i").eq(2).text('请选择').hide();
            //for(var i=1;i<len;i++)
            for ( i in jsonData)
            {
                if(jsonData[i]!=undefined && jsonData[i]['p_region_id']==id)
                {
                    $(".address_con").eq(1).append("<option value="+jsonData[i]["region_id"]+">"+jsonData[i]["local_name"]+"</option>");

                }
            }
            $(".address_con").eq(1).find("option").each(function(index, element) {
                $(element).wrapAll(document.createElement("span"));
            });
            $(".address_tab span").removeClass("atver").eq(1).addClass("atver");
            $(".address_con").hide().eq(1).show();

        }
        if(index==1)
        {
            $(".address_con").eq(2).html('');
            $(".address_tab i").eq(2).text('请选择').show();
            //for(var i=1;i<len;i++)
            for ( i in jsonData)
            {
                if(jsonData[i]!=undefined && jsonData[i]['p_region_id']==id)
                {
                    $(".address_con").eq(2).append("<option value="+jsonData[i]["region_id"]+">"+jsonData[i]["local_name"]+"</option>")

                }
            }
            $(".address_con").eq(2).find("option").each(function(index, element) {
                $(element).wrapAll(document.createElement("span"));
            });
            if($(".address_con").eq(2).text()=='')
            {
                $(".address_tab span").eq(2).hide().html('<i></i>');
                $(".address_text a").text($(".address_tab").text());
                $(".address_select").hide();
                $(".input_addr").val(id);

                $('.page-current').html(1);
                sortGoods($("input#orderValue").val());

            }
            else
            {
                $(".address_tab span").eq(2).show().html('<i>请选择</i>');

            }
            $(".address_tab span").removeClass("atver").eq(2).addClass("atver");
            $(".address_con").hide().eq(2).show();
        }
        if(index==2)
        {
            $(".address_text a").text($(".address_tab").text());
            $(".address_select").hide();
            $(".input_addr").val(id);

            $('.page-current').html(1);
            sortGoods($("input#orderValue").val());

        }
    }


        var laypage = layui.laypage;
        function page(count,curPage){
            laypage.render({
                elem: 'demo7'
                ,count:count,  //当前总页数 默认10
                limit:20,
                curr:curPage
                ,layout: ['count', 'prev', 'page', 'next', 'refresh', 'skip']
                ,jump: function(obj,first){
                    if(!first){//不是第一次 就调用
                        //分页请求
                        console.log(obj.curr);
                        $('.page-current').html(obj.curr)
                        sortGoods($("input#orderValue").val());

                    }
                }
            });
        }


    })
</script>
